<?php namespace Admin\Controller; 
use Hdphp\Controller\Controller;  //框架核心控制器
use Admin\Model\Orders;
class OrdersController extends CommonController{
	private $model;
	public function __init(){
			//载入父级构造函数
		parent::__init();
		$this->model = new Orders;
	}
	//调用主页模板
	public function index(){
			//获取订单数量
		$num = $this->model->count();
			//分页
		$page = Page::row(10)->make($num);
		//获取所有订单
		$data = $this->model->orderBy('time','DESC')->limit(Page::limit())->get();
		//确定订单的状态
		foreach($data as $k => $v){
			if($v['status'] == '未付款'){
				$data[$k]['class'] = 'btn btn-warning';
			}elseif($v['status'] == '已付款'){
				$data[$k]['class'] = 'btn btn-success';
			}elseif($v['status'] == '未发货'){
				$data[$k]['class'] = 'btn btn-primary';
			}elseif($v['status'] == '已发货'){
				$data[$k]['class'] = 'btn btn-info';
			}elseif($v['status'] == '已完成'){
				$data[$k]['class'] = 'btn btn-default';
			}
		}
		View::with('data',$data);
		View::with('page',$page);
		View::make();
	}
		//详情页
	public function detail(){
		//提交数据不为空的时候
		if(IS_POST){
			$data = Q('post.');
			$oid = Q('post.oid',0,'intval');
			//压入数据库
			$this->model->where("oid={$oid}")->save($data);
		}
		//获取订单ID
		$oid = Q('get.oid',0,'intval');
		$uid = Q('get.uid',0,'intval');
		//获取订单信息
		$info = $this->model->join("user",'user_uid','=','uid')->where("oid={$oid} AND user_uid={$uid}")->find();
		$list = Db::table('order_list')->join('goods_list','order_list.glid','=','goods_list.glid')->join('goods','goods_list.goods_gid','=','gid')->where("order_oid={$oid}")->get();
			//设置空数组把组合ID 转换为gavalue
		$arr = array();
		$str = array();
		foreach($list as $k => $v){
			$arr[] = explode('|', $v['combine']);
			foreach($arr[$k] as $key => $value){
				$str[$k][] = Db::table('goods_attr')->where("gaid={$value}")->pluck('gavalue');
			}
		}
		foreach($str as $kk => $vk){
			$list[$kk]['combine'] = implode('/', $vk);
		}
		View::with('list',$list);
		View::with('info',$info);
		View::make();
	}

		//修改
	public function del(){
		//获取要删除订单的ID
		$oid = Q('get.oid',0,'intval');
		//通过模型里面的方法删除
		$this->model->delete($oid);
		//删除订单列表里面的相关数据
		Db::table('order_list')->where("order_oid ={$oid}")->delete();
		go(U('index'));
	}









	
}



?>